package cn.agiledata.bank.linkbank.impl.chinapay;

import cn.agiledata.bank.linkbank.logic.OrderIdTransformer;

/**
 * 中国银联电子支付订单编号转换器。提供支付系统交易编号与向中国银联电子支付提交的订单编号的转换逻辑
 * 
 * @author 马贤波
 * 
 */
public final class ChinapayOrderIdTransformer implements OrderIdTransformer {
    private String merchantId;

    private String date = "";

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String orderId2TransId(String orderId) {
        if (orderId == null || orderId.length() < 7) {
            return orderId;
        }
        return orderId;
    }

    public String transId2OrderId(String transId) {
        if (this.merchantId == null || this.merchantId.length() < 5
                || transId.length() < 7) {
            return transId;
        }
        String tail = this.merchantId.substring(this.merchantId.length() - 5);
        return "0000" + tail + transId.substring(transId.length() - 7);
    }

}
